package cn.wen.yinxiu.netty;import org.springframework.context.ApplicationListener;import org.springframework.context.event.ContextRefreshedEvent;import org.springframework.stereotype.Component;import javax.annotation.Resource;/** * @ClassName: NettyStartListener * @Author: 小飞 * @Date: 2023/6/3 16:33 * @Description: */@Componentpublic class NettyStartListener implements ApplicationListener<ContextRefreshedEvent> {    /**     * 注入启动器     */    @Resource    private WebSocketNettyServer webSocketNettyServer;    @Override    public void onApplicationEvent(ContextRefreshedEvent event) {        //判断event上下文中的父级是否为空        if (event.getApplicationContext().getParent() == null) {            try {                //为空则调用start方法                webSocketNettyServer.start();            } catch (Exception e) {                e.printStackTrace();            }        }    }}